package com.analyse.stock.enums;

import org.apache.commons.lang3.StringUtils;

public enum AnomalyTypeEnum {
    NONE("none","无信号",0),
    FUND_FLOW_IN("0","资金流入异动",1),
    FUND_FLOW_OUT("1","资金流出异动",-1),
    VOLUME_UP("2","股价缩量上涨信息",1),
    VOLUME_DOWN("3","股价放量滞涨信号",-1),
    LONG_UPPER_SHADOW("4","高位长上影信号",-1),
    RSI_OVER_SELL("6","RSI超卖信号-买入信号点",1),
    RSI_OVER_BUY("5","RSI超买-卖出信号点",-1),
    SMA_GOLD_FORK("7","SMA移动平均线金叉-买入信号点",1),
    SMA_DEATH_FORK("8","SMA移动平均线死叉-卖出信号点",-1),
    MACD_GOLD_FORK("9","MACD金叉-买入信号点",1),
    MACD_DEATH_FORK("10","MACD死叉-卖出信号点",-1),
    BOLL_GOLD_FORK("11","BOLL金叉-买入信号点",1),
    BOLL_DEATH_FORK("12","BOLL死叉-卖出信号点",-1),
    KD_GOLD_FORK("13","KD金叉-买入信号点",1),
    KD_DEATH_FORK("14","KD死叉-卖出信号点",-1),
    SAR_BUY("15","SAR-买入信号点",1),
    SAR_SELL("16","SAR-卖出信号点",-1),
    WR_BUY("17","WR-买入信号点",1),
    WR_SELL("18","WR-卖出信号点",-1),
    ;
    AnomalyTypeEnum(String code, String desc,Integer weightVal) {
        this.code = code;
        this.desc = desc;
        this.weightVal = weightVal;
    }

    private final String code;
    private final int weightVal;
    private final String desc;

    public String getCode() {
        return this.code;
    }
    public Integer getWeightVal() {
        return this.weightVal;
    }

    public String getName() {
        return this.desc;
    }

    public String getDesc() {
        return desc;
    }

    public static String getDescByCode(String code){
        if(StringUtils.isBlank(code)) {
            return StringUtils.EMPTY;
        }
        for (AnomalyTypeEnum anEnum : values()) {
            if (anEnum.getCode().equalsIgnoreCase(code)){
                return anEnum.getDesc();
            }
        }
        return StringUtils.EMPTY;
    }

    public static Integer getWeightByCode(String code){
        if(StringUtils.isBlank(code)) {
            return 0;
        }
        for (AnomalyTypeEnum anEnum : values()) {
            if (anEnum.getCode().equalsIgnoreCase(code)){
                return anEnum.getWeightVal();
            }
        }
        return 0;
    }

    public static String getByName(String name){
        if(StringUtils.isBlank(name)) {
            return StringUtils.EMPTY;
        }
        for (AnomalyTypeEnum anEnum : values()) {
            if (anEnum.name().contains(name.toUpperCase())){
                return anEnum.getCode();
            }
        }
        return StringUtils.EMPTY;
    }
}
